'use strict'
import Nova from './nova'
import Auth from './auth'
import cache from '../utils/cache'
class ECTest {
  constructor() {
    this.nova = new Nova()
    this.auth = new Auth()
  }
  async init() {
    this.token = await this.getToken()
    cache.set('token', this.token)
    return this
  }
  async exec(module, task, params, isExecArray) {
    if (!Array.isArray(params) || (Array.isArray(params) && isExecArray === true)) {
      return await this[module][task](params)
    } else {
      return await this[module][task](...params)
    }
  }
  async getToken() {
    let storageToken = await this.auth.checkStorageToken()
    if (!storageToken) {
      return await this.auth.fetchToken()
    } else {
      return storageToken
    }
  }
}
export default ECTest
